package com.loie.xcx;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.loie.xcx.syUtil.HttpUtil;
import com.loie.xcx.web.DataCenterApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.junit4.SpringRunner;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID;


/**
 * @author: kw
 * @description: 签名连通测试
 * @create: 2021/11/18 15:16
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DataCenterApplication.class)
@Slf4j
@MapperScan("com.loie.xcx.mapper")
public
class decodetest {
    private String CHANNEL = "bosc-qcjj";
    private String urlPrefix = "https://bosccloud.qhhrly.cn/cloud/std";

    private String urlPrefixPrd = "https://bosccloud.qhhrly.cn/cloud/std";

    @Autowired
    private ResourceLoader resourceLoader;
    @Test
    public void reoucetadd_test(){
        //Resource resource = resourceLoader.getResource("classpath:/");

            String dest=System.getProperty("user.dir")+"\\src\\main\\resources\\";
          //  System.getProperty("user.dir")
            System.out.println(dest);

    }

    @Test
    public void encode() throws  Exception{
        String code = "0000";
        String resultMsg = "接收成功";
        JSONObject resultData = new JSONObject();

        //resultData.put("projectId", 6625325769688092672L);
        //resultData.put("coreCompanyName", data);
        resultData.put("code", code);
        resultData.put("msg", resultMsg);

        String result = HttpUtil.encode_key(CHANNEL, resultData, false, false, "", UUID.randomUUID().toString());
        //9. 返回
        String ret = JSON.toJSONString(result);
        System.out.println("ret==>"+ret);
    }

    @Test
    public void decode() throws  Exception{
        String path="/Apidoc/encode.json";
        Resource resource = new ClassPathResource(path);
        byte[] bytes = Files.readAllBytes(Paths.get(resource.getURI()));
        String ret=new String(bytes, StandardCharsets.UTF_8);
        System.out.println(ret);
        String data=HttpUtil.decode_key(CHANNEL,ret,false,"");
        System.out.println("解密数据:"+data);
    }



}
